package com.howtoplay.Configraution;

import com.howtoplay.Handler.Handshake.WebSocketHandShake;
import com.howtoplay.Handler.WebsocketBinaryHandler;
import com.howtoplay.Handler.WebsocketTextHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.*;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        WebSocketHandShake handShake = new WebSocketHandShake();
        webSocketHandlerRegistry.addHandler(new WebsocketBinaryHandler(), "/byte").setAllowedOrigins("*")
                .addInterceptors(handShake);
        webSocketHandlerRegistry.addHandler(new WebsocketTextHandler(), "/txt").setAllowedOrigins("*").addInterceptors(handShake);
    }
}
